package com.matrix.java.chap_08.example;

import com.matrix.java.chap_08.util.ArrayUtil;

import java.util.Arrays;
import java.util.Scanner;

public class Case8_03 {
    public static void main(String[] args) {
        ArrayUtil arrayUtil = new ArrayUtil();
        Scanner input = new Scanner(System.in);
        System.out.print("Enter the number of points: ");
        int numberOfPoints = input.nextInt();
        double[][] points = arrayUtil.inputInitDoubleMatrix(numberOfPoints, 2);
        double minDistance = calculateDistance(points[0], points[1]);
        int indexOfMinDistance = 1;
        for (int i = 2; i < points.length; i++) {
            double distance = calculateDistance(points[i], points[i - 1]);
            if (distance < minDistance) {
                minDistance = distance;
                indexOfMinDistance = i;
            }
        }
        System.out.println(Arrays.toString(points[indexOfMinDistance]) + "\t" + Arrays.toString(points[indexOfMinDistance - 1]));
        input.close();
    }

    static double calculateDistance(double[] arr1, double[] arr2) {
        return Math.sqrt(Math.pow((arr1[0] - arr2[0]), 2) + Math.pow((arr1[1] - arr2[1]), 2));
    }
}
